package cn.csxw.openchina.base;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.FragmentStatePagerAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by hp on 2017/1/14.
 *
 * 这个是带有TabLayout+ViewPager的ViewPagerAdapter的基类。只有子类添加了标题数组和fragment的集合就行了
 */

public class BaseContentPagerAdapter extends FragmentPagerAdapter {
    private List<BaseRefreshFragment> refreshList = new ArrayList<>();
    private String [] title;
   public void setSwipeList(List<BaseRefreshFragment> refreshList, String [] title){
       this.refreshList = refreshList;
           this.title  = title;
       notifyDataSetChanged();
   }

    public BaseContentPagerAdapter(FragmentManager fm) {
        super(fm);
    }
    @Override
    public Fragment getItem(int position) {
        return refreshList.get(position);
    }

    @Override
    public int getCount() {
        return refreshList.size();
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return (title==null || title.length== 0)? null:title[position];
    }
}
